import Vue from 'vue'
import Vuex from 'vuex'

import app from './modules/app'
import tagsView from './modules/tagsView'

import user from './modules/user'
import setting from './modules/setting'

Vue.use(Vuex)

const store = new Vuex.Store({
  // 引用模块
  modules: {
    app,
    user,
    setting,
    tagsView
  },
  state: {
  },
  // 操作异步操作mutations
  actions: {
    // 清除缓存
    clear({ commit }) {
      store.dispatch('setting/clear')
      store.dispatch('user/clear')
    }
  },
  mutations: {
    mapChangeAddress(state, mapChangeAddress) {
      state.mapChangeAddress = mapChangeAddress
    },
    requestUrl(state, requestUrl) {
      state.requestUrl = requestUrl
    }
  },
  getters: {
    url: state => state.setting.url,

    token: state => state.user.token,
    avatar: state => state.user.avatar,
    name: state => state.user.userName,
    menus: state => state.user.menus,
    menu: state => state.user.menu,

    sidebar: state => state.app.sidebar,
    device: state => state.app.device
  }
})

export default store
